<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/shopcar.css">
    <script src="../js/jquery-3.5.1.js"></script>
    <script src="../js/utils.js"></script>
</head>

<body>
    <header>
        <div class="_t"><img src="../img/T.png" alt=""></div>
        <ul>
            <li class="active">
                <a href="../index.html">在线商城</a>
            </li>
            <li>
                坚果 R2
            </li>
            <li>
                <a href="./TNT_go.html">Smartisan TNT go</a>
            </li>
            <li>
                坚果 TNT 工作站
            </li>
            <li>
                Smartisan OS
            </li>
            <li>
                欢喜云
            </li>
            <li>
                应用
            </li>
            <li>
                论坛
            </li>
            <li>
                开发者支持
            </li>
            <li>
                荣誉与奖项
            </li>
            <li>
                加入我们
            </li>
            <li tabs-item-apps">
                下载 APP
            </li>
        </ul>
        <div class="h_r">
            <div class="icon_1"></div>
            <div class="icon_2"></div>
        </div>
    </header>
    <div class="top">
        <div class="top_content">
            <ul>
                <li class="active">概览</li>
                <li>OS 2.0</li>
                <li>技术规格</li>
            </ul>
            <div class="top_content_right">
                <input type="text">
                <img src="../img/1625536877263.jpg" alt="" id="search">
                <button class="btn_R2">坚果 R2</button>
                <button class="btn_TNT">TNT</button>
            </div>
        </div>
    </div>
    <div class="content">
        <ul class="neirong">
        </ul>
        <div class="foot">
            <div class="foot_left"><span class="span_1">总价 ： ¥</span><span class="span_2"></span></div>
            <div class="foot_right"><button>结算</button></div>
        </div>
    </div>
    <footer>
        <div class="footer_content">
            <div class="footer_content_top">
                <ul class="footer_left">
                    <li>
                        <h5>订单服务</h5>
                        <p>购买指南</p>
                        <p>送货政策</p>
                    </li>
                    <li>
                        <h5>服务支持</h5>
                        <p>自助服务</p>
                        <p>维修门店</p>
                    </li>
                    <li>
                        <h5>媒体中心</h5>
                        <p>新闻动态</p>
                        <p>官方视频</p>
                        <p>图片资源</p>
                    </li>
                    <li>
                        <h5>关注我们</h5>
                        <p>新浪微博</p>
                        <p>官方微信</p>
                        <p>荣誉奖项</p>
                    </li>
                </ul>
                <div class="right">
                    <h3>400 - 603 - 5000</h3>
                    <h5>周一到周日 9:00 - 18:00</h5>
                    <h5>(仅收市话费)</h5>
                    <button class="help">在线帮助</button>
                </div>
            </div>
            <div class="footer_content_bottom">
                <ul class="footer_bottom_top">
                    <li>Copyright © 2020 smartisan.com 版权所有</li>
                    <li>锤子商城隐私政策</li>
                    <li>锤子商城用户协议</li>
                    <li>资质证照</li>
                </ul>
                <ul class="footer_bottom_bottom">
                    <li>京 ICP 备 19048576 号 - 1</li>
                    <li><img src="../img/icon5.png" alt="" id="police"><span>京公网安备 11010502039854号</span></li>
                    <li>京食药网食备 202010031</li>
                </ul>
            </div>
        </div>
    </footer>
    <div class="gotop">回到顶部</div>
    <script>
        ajax({
            url: 'http://10.9.46.151:8080/list',
            method: 'GET',
            success(res) {
                res = JSON.parse(res)
                var str = ''
                var zzprice = 0;
                for (let i = 0; i < res.length; i++) {
                    if (res[i].num > 0) {
                        str += `
                        <li class="${res[i].sku_id}">
                            <div class="left"><img src="${res[i].ali_image}"></img></div>
                            <div class="name">${res[i].name}</div>
                            <div class="change">
                                <button class="jian" sku_id="${res[i].sku_id}">-</button>
                                <p>${res[i].num}</p>
                                <button class="jia" sku_id="${res[i].sku_id}">+</button>
                            </div>
                            <div class="price">${"单价 ： ¥" + res[i].price}</div>
                            <div class="zprice">${"总价 ： ¥" + res[i].price * res[i].num}</div>
                            <button class="clear" sku_id="${res[i].sku_id}">移除该商品</button>
                        </li>                
                    `
                        zzprice += res[i].price * res[i].num
                        $('.span_2').text(zzprice)
                        $('.neirong').html(str)
                    }


                }

            }
        })

    </script>
    <script>
        window.onload = function () {
            $('.jian').on('click', function (e) {
                var xhr = new XMLHttpRequest();
                xhr.addEventListener("load", () => {
                    res = JSON.parse(xhr.response)
                    for (let i = 0; i < res.length; i++) {
                        if (res[i].sku_id == $(this).attr('sku_id')) {
                            res[i].num--
                            if (res[i].num <= 0) {
                                const coc = JSON.stringify(res[i])
                                ajax({
                                    url: 'http://10.9.46.151:8080/delgoods',
                                    data: coc,
                                    dataType: "json",
                                    method: 'POST',
                                    success(res) {

                                    }
                                })
                            } else {
                                const coc = JSON.stringify(res[i])
                                ajax({
                                    url: 'http://10.9.46.151:8080/changegoods',
                                    data: coc,
                                    dataType: "json",
                                    method: 'POST',
                                    success(res) {

                                    }
                                })
                            }


                        }
                    }
                    location.reload()
                });
                xhr.open("GET", "http://10.9.46.151:8080/list");
                xhr.send();

            })
            $('.jia').on('click', function (e) {
                var xhr = new XMLHttpRequest();
                xhr.addEventListener("load", () => {
                    res = JSON.parse(xhr.response)
                    for (let i = 0; i < res.length; i++) {
                        if (res[i].sku_id == $(this).attr('sku_id')) {
                            res[i].num++
                            const coc = JSON.stringify(res[i])
                            ajax({
                                url: 'http://10.9.46.151:8080/changegoods',
                                data: coc,
                                dataType: "json",
                                method: 'POST',
                                success(res) {

                                }
                            })
                        }
                    }
                    location.reload()
                });
                xhr.open("GET", "http://10.9.46.151:8080/list");
                xhr.send();

            })
            $('.clear').on('click', function (e) {
                var xhr = new XMLHttpRequest();
                xhr.addEventListener("load", () => {
                    res = JSON.parse(xhr.response)
                    for (let i = 0; i < res.length; i++) {
                        if (res[i].sku_id == $(this).attr('sku_id')) {
                            const coc = JSON.stringify(res[i])
                            ajax({
                                url: 'http://10.9.46.151:8080/delgoods',
                                data: coc,
                                dataType: "json",
                                method: 'POST',
                                success(res) {

                                }
                            })
                        }
                    }
                    location.reload()
                });
                xhr.open("GET", "http://10.9.46.151:8080/list");
                xhr.send();
            })
            $('.foot_right > button').on('click',function(e){
                var xhr = new XMLHttpRequest();
                xhr.addEventListener("load", async function() {
                    res = JSON.parse(xhr.response)
                    for (let i = 0; i < res.length; i++) {
                            console.log('aaa');
                            let vov = JSON.stringify(res[i])
                            ajax({
                                url: 'http://10.9.46.151:8080/delgoods',
                                data: vov,
                                dataType: "json",
                                method: 'POST',
                                success(res) {
                                    location.reload()
                                }
                            })
                        
                    }
                    
                });
                xhr.open("GET", "http://10.9.46.151:8080/list");
                xhr.send();
            })
        }
    </script>
    <script>
    </script>
</body>

</html>